﻿using System;
using System.Collections;
using System.Collections.Generic;
using FlowCanvas;
using FlowCanvas.Nodes;
using LogSystem;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
using Yoozoo.Gameplay.Liberty.AI;

namespace Yoozoo.Gameplay.Liberty.StreetEvent
{
    public class ChangeMonsterStatus : CallableActionNode<string, float,SideType ,NpcStatus,bool>
    {
        public override void Invoke(string pointName, float radius, SideType sideType, NpcStatus npcStatus, bool autoRevenge)
        {
            var npcBirthMgr = LibertyAIUtils.AIManager.NpcBirthManager;
            BluePrintPoint point = BlueprintUtils.GetBlueprintPoint(pointName);
            if (point != null)
            {
                foreach (var aiEntity in npcBirthMgr.AIEntities)
                {
                    if (aiEntity.Value.data.side == sideType)
                    {
                        if (Vector3.Distance(aiEntity.Value.viewer.transform.position,point.position) < radius)
                        {
                            if (aiEntity.Value.data.npcStatus != npcStatus)
                            {
                                aiEntity.Value.data.npcStatus = npcStatus;
                                
                                aiEntity.Value.viewer.animationAgent.PlayIdleAnimation();

                                if (npcStatus == NpcStatus.Battle && autoRevenge)
                                {
                                    aiEntity.Value.battleAgent.revengeTarget = LibertyAIUtils.GetPlayerEntity();
                                    aiEntity.Value.battleAgent.revengeColdDuration = -1;  // 永久仇恨
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}